package com.dave.gd.core.base.repository;

import java.io.Serializable;

import com.dave.gd.common.util.spring.ApplicationContextUtil;
import com.dave.gd.core.base.entity.impl.AbstractBaseEntity;

@SuppressWarnings("rawtypes")
public class RepositoryRegister {
    private static class RepositoryRegisterHolder {
        private static RepositoryRegister INSTANCE = new RepositoryRegister();
    }
    
    public static RepositoryRegister getInstance() {
        return RepositoryRegisterHolder.INSTANCE;
    }
    
    private RepositoryFactory factory;
    
    private RepositoryRegister() {
        factory = new RepositoryFactory();
    }
    
    public <T extends AbstractBaseEntity<I>, I extends Serializable> IBaseRepository<T, I> getRepository(
        final Class<T> c) {
        return factory.getRepository(c);
    }
    
    public IBaseRepository getDefaultRepository() {
        return ApplicationContextUtil.getBean("defaultRepository");
    }
    
}
